home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
MACSHELL
/
MS1
/
GENERICP.ROC
< prev
next >
Wrap
Text File
|
1992-12-02
|
8KB
|
277 lines
/*
* MacShell Source File
*
* Generic Procs for building new commands
*
* Copyright (c) 1989, 1990, 1991, 1992 Suick Bay Technologies. All rights reserved.
*
*
* RESTRICTIONS ON MacShell program and source code.
*
* Ñ╩MacShell¬ is a product of Suick Bay Technologies and is provided for
* restricted use by the owner of the CDROM "Disk to the future II".
*
* Ñ╩No permission is granted for any commercial use without the written
* consent of the Suick Bay Technologies.
*
* Ñ╩No permission is granted for any redistribution of any kind use without
* the written consent of the Suick Bay Technologies.
*
* Ñ╩Permission is granted to use this for any personal noncommercial use.
*
* Ñ╩You may not distribute source or executable code at all, nor may you
* distribute it with or within a commercial product without the written
* consent of the Suick Bay Technologies. Please send modifications to
* the author for inclusion in updates to the program. Thanks.
*
*
* MacShell¬ IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* SUICK BAY TECHNOLOGIES SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY MACSHELL
* OR ANY PART THEREOF.
*
* In no event will Suick Bay Technologies be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Suick Bay Technologies has been advised of the possibility of such damages.
*
* Suick Bay Technologies can be reached at:
*
* 8768 Cottonwood lane
* Maple Grove, MN 55369
* Voice: (612) 425-7025
* AppleLink: D5233
*
*
* No parts of this software may be reproduced or stored in a
* retrieval system or transmitted in any form, or any means,
* electronic, mechanical, photocopying, recording or otherwise,
* without the prior written permission of Suick Bay Technologies.
*
* Spread the word and not the disk.
*
* This file contains 'Generic' process functions that can be used
* create new commands. Two formats are provided. The first
* format is used for simple commands that do not require path
* searching. Simple commands that were created from this format
* were echo, sleep, etc. The second format is used for commands that
* process files. These commands rquire the use of the ExpandPath
* function and a call-back function. ExpandPath is passed a
* path that is used to search for a file, directory or volume.
* When a match is found, the ExpandPath function then calls the
* provided callback function with the appropriate information.
* This feature allows the shell to expand 'wildcard' patterns
* that are specified in path names.
*
* The functions are listed with XXX and YYY in their names. in
* general the XXX should be substituted with the function name.
* For example wc (for word count). THe YYY should be substituted
* with the type of date that the function operates on. For
* example File.
*
* For examples of procs that use stdin refer to the command
* source code product.
*
*/
#include "SystemPub.h"
#include "Proc.h"
#include "ShellPub.h"
#include "Prefs.h"
/*******************************************************************
*
* Function XXX
*
* usage XXX [options] [names]
*
*
*******************************************************************/
void XXXYYY( WHandle ShellWh, int16 PID, char *argument )
{
/*
* Process the argument here
*/
procPrintf( ShellWh, PID, "XXXYYY arg %s\n", argument );
}
/*******************************************************************/
Boolean DoXXX( int16 signal, WHandle ShellWh, int16 PID,
char *string )
{
int16 i, argc;
char *cp, argument[ 256 ];
ShellWindRec **MyShell = (ShellWindRec **) (**ShellWh).thing;
switch( signal )
{
case PROC_INIT :
(**MyShell).Proc[ PID ].flags = TRUE; /* flag the init */
break;
case PROC_TERM : /* user break or quit ! */
case PROC_BREAK :
/* Tell the shell that we're done */
SendOutToken( ShellWh, PID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ PID ].ProcActive = FALSE;
break;
case PROC_STDIN :
if( (**MyShell).Proc[ PID ].flags ) /* were we inited ? */
{
(**MyShell).Proc[ PID ].flags = FALSE; /* we only want to execute once */
/* get arguments */
argc = (**MyShell).Proc[ PID ].argc; /* number of arguments */
for( i = 1; i < argc; i++ ) /* process options first */
{
GetArgv( ShellWh, PID, i, argument );
cp = argument;
if( *cp++ == '-' )
while( *cp ) /* scan characters after - */
switch( *cp++ )
{
case 'x' : /* option x */
/* set option flags here */
break;
}
}
for( i = 1; i < argc; i++ ) /* process arguments next */
{
GetArgv( ShellWh, PID, i, argument );
if( *argument != '-' ) /* don't process options */
{
XXXYYY( ShellWh, PID, argument );
ResetShellPWD( ShellWh );
}
}
/* Tell the shell that we're done */
SendOutToken( ShellWh, PID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ PID ].ProcActive = FALSE;
return( TRUE ); /* return status */
}
}
}
/*******************************************************************
*
* Function XXX
*
* PathName Callback function
*
* usage XXX [options] [names]
*
*
*******************************************************************/
void XXXCallBack( WHandle ShellWh, int16 PID,
char *path, /* full path to this object */
char *last, /* name of this object */
pathType what, /* what the object is */
int16 vRefNum, /* objects volume reference number */
int32 dirID ) /* objects directory ID */
{
switch( what )
{
case pathIsFile : /* process file */
procPrintf( ShellWh, PID, "XXXYYY found FILE %s\n", last );
break;
case pathIsDir : /* process directory */
procPrintf( ShellWh, PID, "XXXYYY found DIRECTOY %s\n", path );
break;
case pathIsVol : /* process volume */
procPrintf( ShellWh, PID, "XXXYYY found VOLUME %s\n", last );
break;
}
}
void XXXYYY( WHandle ShellWh, int16 PID, char *argument )
{
ShellWindRec **MyShell;
/* get the shells date object */
MyShell = (ShellWindRec **) (**ShellWh).thing;
/* expand pathname */
ExpandPath( ShellWh, PID, argument, XXXCallBack,
(**MyShell).pwdVRefNum, (**MyShell).pwdDirID );
/* reset the shell to its previous working directory */
ResetShellPWD( ShellWh );
}
/*******************************************************************/
Boolean DoXXX( int16 signal, WHandle ShellWh,
int16 PID, char *string )
{
int16 i, argc;
char *cp,
argument[ 256 ];
ShellWindRec **MyShell = (ShellWindRec **) (**ShellWh).thing;
switch( signal )
{
case PROC_INIT :
(**MyShell).Proc[ PID ].flags = TRUE; /* flag the init */
break;
case PROC_TERM :
case PROC_BREAK :
/* Tell the shell that we're done */
SendOutToken( ShellWh, PID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ PID ].ProcActive = FALSE;
break;
case PROC_STDIN :
if( (**MyShell).Proc[ PID ].flags )
{
(**MyShell).Proc[ PID ].flags = FALSE; /* we only want to execute once */
/* get arguments */
argc = (**MyShell).Proc[ PID ].argc;
for( i = 1; i < argc; i++ )
{
GetArgv( ShellWh, PID, i, argument );
cp = argument;
if( *cp++ == '-' )
while( *cp )
switch( *cp++ )
{
case 'x' : /* option x */
break;
}
}
for( i = 1; i < argc; i++ )
{
GetArgv( ShellWh, PID, i, argument );
if( *argument != '-' ) /* don't process options */
XXXYYY( ShellWh, PID, argument );
}
/* Tell the shell that we're done */
SendOutToken( ShellWh, PID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ PID ].ProcActive = FALSE;
return( FALSE );
}
}
}